package com.example.demo1.insurance;

import java.util.Scanner;
public class Baoxian2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double age = 0;
        String sex = "";
        String marry = "";
        double people = 0;
        double money = 0;
        int count = 0;
        double sum = 0;

        while (true) {
            System.out.println("请输入年龄（1~99）：");
            try {
                age = scanner.nextDouble();
            } catch (Exception e){
                System.out.println("请输入数字!");
                System.exit(0);
            }
            if ((int) age != age) {
                System.out.println("请输入整数！");
            } else {
                if (age >= 1 && age <= 99) {
                    if (age < 20 || age > 60) {
                        count += 2;
                    } else if (age < 40) {
                        count += 6;
                    } else {
                        count += 4;
                    }
                    break;
                } else {
                    System.out.println("请输入规定范围内的年龄！");
                }
            }
        }

        while (true) {
            System.out.println("请输入性别（男M/女F）：");
            sex = scanner.next();
            if (sex.equals("M")) {
                count += 5;
                break;
            } else if (sex.equals("F")){
                count += 3;
                break;
            } else {
                System.out.println("请勿输入“M”和“F”以外的非法字符！");
            }
        }

        while (true) {
            System.out.println("是否已婚（Y/N）：");
            marry = scanner.next();
            if (marry.equals("Y")) {
                count += 3;
                break;
            } else if (marry.equals("N")){
                count += 5;
                break;
            } else {
                System.out.println("请勿输入“Y”和“N”以外的非法字符！");
            }
        }

        while (true) {
            System.out.println("请输入抚养人数（0~9）：");
            try {
                people = scanner.nextDouble();
            } catch (Exception e){
                System.out.println("请输入数字!");
                System.exit(0);
            }
            if ((int) people != people) {
                System.out.println("请输入整数！");
            } else {
                if (people >= 0 && people <= 9) {
                    sum = people * 0.5;
                    if ((int) sum != sum) {
                        sum += 0.5;
                    }
                    if (sum > 3) {
                        sum = 3;
                    }
                    count -= sum;
                    break;
                } else {
                    System.out.println("请输入规定范围内的人数！");
                }
            }
        }

        while (true) {
            System.out.println("请输入投保额（100000~5000000）：");
            try {
                money = scanner.nextDouble();
            } catch (Exception e){
                System.out.println("请输入数字!");
                System.exit(0);
            }
            if (money >= 100000 && money <= 5000000) {
                break;
            } else {
                System.out.println("请输入规定范围内的投保额！");
            }
        }

        if (count < 10) {
            System.out.println("您的人寿保险保费为：" + money * 0.001);
        } else {
            System.out.println("您的人寿保险保费为：" + money * 0.006);
        }
    }
}

